package com.jitu.bigscreen.test;

import com.jitu.bigscreen.component.LedControlInf;
import com.jitu.bigscreen.model.Date;
import com.jitu.bigscreen.model.*;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author wangwl
 * added by wangwl at 20200320
 */
public class test_216 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int retValue = -1;
		String ip = "192.168.0.101\0";
        byte[] iptobytes = ip.getBytes();

		try {
			//1、初始化
			 LedControlInf.INSTANCE.LV_InitDllEx(1);

//			 //2、执行操作指令

			 //发送节目操作
//			 btMulProgram_Click(iptobytes);

//			 btMulProgramByPeriod_Click(iptobytes,10);
//			 btMulProgramByInsert_Click(iptobytes);


			 //压力测试发节目操作
			 processConcurrentTest(iptobytes);

			 //获取设备信息操作
//			 btGetDeviceInfo_Click(iptobytes);

		} catch (Exception e) {
			// TODO: handle exception
		  System.out.println(e);
		}
	}

	private static boolean isTimeRangeS(String strStartDate,String strEndDate)throws ParseException {
		 SimpleDateFormat df = new SimpleDateFormat("HH:mm");
		 java.util.Date now = df.parse(df.format(new java.util.Date()));
		 java.util.Date begin = df.parse(strStartDate);
		 java.util.Date end = df.parse(strEndDate);
		 Calendar nowTime = Calendar.getInstance();
		 nowTime.setTime(now);
		 Calendar beginTime = Calendar.getInstance();
		 beginTime.setTime(begin);
		 Calendar endTime = Calendar.getInstance();
		 endTime.setTime(end);
		    if (nowTime.before(endTime) && nowTime.after(beginTime)) {
		        return true;
		    } else {
		        return false;
		    }
	}

	//压力测试节目发送
	public static void processConcurrentTest( byte[] iptobytes) throws ParseException
	{
		while(true){
			 try {

				 if(isTimeRangeS("07:00","08:30")||isTimeRangeS("10:00","12:00")||isTimeRangeS("14:00","17:00")||isTimeRangeS("17:30","18:30")){

					 btMulProgramByPeriod_Click(iptobytes,10);

					 Thread.sleep(2*60*1000);
				 }

			 }catch (InterruptedException e) {
		            e.printStackTrace();
		      }
		}
	}
	 //获取设备信息
   private static void btGetDeviceInfo_Click(byte[] pIp)
   {
		int retValue = 0;
		byte[] pVersionInfo = new byte[2048];
		try {
			retValue = LedControlInf.INSTANCE.LV_GetDeviceVersion(pIp, pVersionInfo,pVersionInfo.length);
			System.out.println(new String(new String(pVersionInfo).getBytes("ISO8859_1"),"UTF-8"));
	        System.out.println(retValue == 0 ? "获取设备信息成功" : "获取设备信息失败");
		} catch (Exception e) {
			// TODO: handle exception
		}

   }

   private static void btMulProgram_Click(byte[] iptobytes) throws ParseException
  {

	   String screenName1 ="test1";
	   String pProgramId = "19";
	   String pProgramName = "19";

	   byte[] pProgramIdToBytes = (pProgramId + "\0") .getBytes();
	   byte[] pProgramNameToBytes = (pProgramName + "\0").getBytes();
	   byte[] screenNameToBytes = (screenName1 + "\0") .getBytes();

	   String rootPath = System.getProperty("user.dir")+"\\resources\\";

	    byte[] errByt =new byte[2048];
	   try {

		 int retValue = 0;
      retValue = LedControlInf.INSTANCE.LV_ClearProgram(screenNameToBytes);
      System.out.println("LV_ClearProgram = " + retValue);

      Random rd = new Random();
      int pageId = rd.nextInt(100);
      //直行
      String src1 = rootPath + "88.jpg";

      //*****************第一步 添加节目页面***********************************************************************
      Page page = new Page();
      page.setPageId(pageId);
      page.setResolution("1920X1080");
      page.setBgColor("#000000");
      page.setBgImg("");
      page.setEqType("Q5");
      page.setPageTime(10);
      UUID uuid = UUID.randomUUID();
      page.setGuid(uuid.toString());

       //对象转为Json
      ObjectMapper mapper = new ObjectMapper();
      String pPageJson = mapper.writeValueAsString(page);
      System.out.println(pPageJson);

      byte[] pageJsontoBytes = pPageJson.getBytes();
      int resurt1 = LedControlInf.INSTANCE.LV_AddPageToProgram(screenNameToBytes, pProgramIdToBytes, pageJsontoBytes);

//      byte[] errByt = new byte[2048];
//      retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//
//      System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
      System.out.println(resurt1 == 0 ? "添加节目页面成功" : "添加节目页面失败");

      //*****************第二步 在节目页面上添加对应的显示区域*********************************************************

      //图片区域
      PictureArea a = new PictureArea();
      a.setId(1);
      a.setType(1);
      a.setBorderEffect(0);
      a.setBorderSW(0);
      a.setBorderSpeed(0);
      a.setBorderType(0);
      a.setLeft(0);
      a.setTop(0);
      a.setWidth(128);
      a.setHeight(128);
      a.setPauseTime(5);
      a.setRotation(0);
      a.setSiderType(6);
      List<SrcGroup> lsg = new ArrayList<SrcGroup>();
      a.setSrcGroup(lsg);

      SrcGroup s = new SrcGroup();
      s.setId(1);
      s.setSrc(src1);
      a.getSrcGroup().add(s);

      SrcGroup s1 = new SrcGroup();
      s1.setId(2);
      src1 = rootPath + "83.jpg";
      s1.setSrc(src1);
      a.getSrcGroup().add(s1);
      a.setzIndex(0);

      //对象转为Json
      String ajson = mapper.writeValueAsString(a);

      System.out.println(ajson);

      byte[] ajsontobytes = ajson.getBytes();
//      int resurt2 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, ajsontobytes);
      int resurt2 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, ajsontobytes);
//      retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//      System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
      System.out.println(resurt2 == 0 ? "添加图片区域成功" : "添加图片区域失败");


    //视频区域
      VideoArea videoArea = new VideoArea();
      videoArea.setId(3);
      videoArea.setType(0);
      videoArea.setBorderEffect(1);
      videoArea.setBorderSW(1);
      videoArea.setBorderSpeed(1);
      videoArea.setBorderType(9);
      videoArea.setLeft(0);
      videoArea.setTop(256);
      videoArea.setWidth(288);
      videoArea.setHeight(96);
      videoArea.setPauseTime(5);
      videoArea.setRotation(0);
      videoArea.setSiderType(6);
      List<SrcGroup> lsgVideoArea = new ArrayList<SrcGroup>();
      videoArea.setSrcGroup(lsgVideoArea);

      src1 = rootPath + "21.mp4";
      SrcGroup sVideoArea = new SrcGroup();
      sVideoArea.setId(1);
      sVideoArea.setSrc(src1);
      videoArea.getSrcGroup().add(sVideoArea);

      SrcGroup sVideoArea1 = new SrcGroup();
      sVideoArea1.setId(2);
      src1 = rootPath + "23.mp4";
      sVideoArea1.setSrc(src1);
      videoArea.getSrcGroup().add(sVideoArea1);
      videoArea.setzIndex(0);

      //对象转为Json
      String vjson = mapper.writeValueAsString(videoArea);

      System.out.println(vjson);

      byte[] vjsontobytes = vjson.getBytes();
//      int resurt3 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, vjsontobytes);
      int resurt3 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, vjsontobytes);
//      retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//      System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
      System.out.println(resurt3 == 0 ? "添加视频区域成功" : "添加视频区域失败");


      //文本区域
      TextArea textArea = new TextArea();
      //id
      textArea.setId(2);
  	//type Int 区域素材类型，字幕对应的类型为:2
      textArea.setType(2);
  	//borderSW Int 区域边框开关 1:开 0:关
      textArea.setBorderSW(0);
   	//borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
      textArea.setBorderEffect(0);
  	//颜色特效 0:无 1:水平渐变 2:垂直渐变 3:斜角渐变
      textArea.setColorEffect(0);
  	//borderSpeed int 区域边框速度 0~4
      textArea.setBorderSpeed(0);
  	//borderType Int 区域边框类型 0~9 详见附录
      textArea.setBorderType(0);
  	//left Int 区域 x 坐标点
      textArea.setLeft(256);
  	//top Int 区域 y 坐标点
      textArea.setTop(0);
  	//width Int 区域宽度
      textArea.setWidth(256);
  	//height Int 区域高度
      textArea.setHeight(64);
  	//background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
      textArea.setBackground("#000000");
  	//fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
      textArea.setFontColor("#00ff00");
  	//fontFamily String 文字字体,如”宋体”
      textArea.setFontFamily("宋体");
  	//fontSize Int 字体大小 12~128 ,单位 px
      textArea.setFontSize(48);
  	//italic Int 是否斜体 1:是 0:否
      textArea.setItalic(0);
  	// bold Int 是否粗体 1:是 0:否
      textArea.setBold(1);
  	//textLine Int 文字线 0:无 1:下划线 2:删除线
      textArea.setTextLine(0);
  	//lineHeight Int 行间距,多行时有效
      textArea.setLineHeight(5);
  	//pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
      textArea.setPauseTime(5);
  	//scrollSpeed Int 字幕滚动速度 0~14
      textArea.setScrollSpeed(2);
  	//siderType Int 滚动方式 0:静止 1:向左移动 2:向左连续移动 3:向右移动 4:向右连续移动
      textArea.setSiderType(2);
  	//textAlign Int 对齐方式 0:左,1:中间 2:右
      textArea.setTextAlign(0);

      textArea.setTextTop(0);

      String strTextInfo = "AAAA灵信视觉二次开发动态库文本发送";
//      String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
      textArea.setText(strTextInfo);
  	//textShow Int 字幕显示方式 1:单行 0:多行
      textArea.setTextShow(1);
  	//zIndex int 层级
  	textArea.setzIndex(0);

     //对象转为Json
     String tjson = mapper.writeValueAsString(textArea);

     System.out.println(tjson);

     byte[] tjsontobytes = tjson.getBytes();
//     int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
     int resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, tjsontobytes);
//     retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//     System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
     System.out.println(resurt4 == 0 ? "添加文本区域成功" : "添加文本区域失败");

     //*****************第三步 发送节目内容*********************************************************

  	//节目发送
//      retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(iptobytes);

      retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(screenNameToBytes,iptobytes,pProgramIdToBytes,pProgramNameToBytes,new byte[0]);
//      if(retValue != 0){
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//      }
      System.out.println(retValue == 0 ? "节目内容发送成功" : "节目内容发送失败");

      //*****************第四步 发送节目计划,执行播放节目指令 *********************************************************
      String pDefResVideoFile ="\0";

//      MulProgram mulProgram = new MulProgram();

      List<MulProgram> lsMulProgram = new ArrayList<MulProgram>();

      List<ProgramPlan> lsProgramPlan = new ArrayList<ProgramPlan>();
      ProgramPlan programPlan = new ProgramPlan();
      programPlan.setCreateDate(String.valueOf(new java.util.Date().getTime()));
      List<Date> lsDate = new ArrayList<Date>();

      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//      Calendar.getInstance().
      Date date = new Date();
      date.setDateStart(formatter.parse("2020-03-30").getTime());
      date.setDateEnd(formatter.parse("2020-04-30").getTime());
      lsDate.add(date);
      programPlan.setDate(lsDate);
      programPlan.setIsDefault(0);
      List lsPlanWeekDay = new ArrayList();
      for(int k=0;k<=6;k++){

          lsPlanWeekDay.add(1);
      }

      programPlan.setPlanWeekDay(lsPlanWeekDay);
      programPlan.setProgramId(pProgramId);
      programPlan.setProgramName(pProgramName);
      programPlan.setProgramType(1);////1:轮播节目(该类型节目最多只能1个) 2:插播节目 3:定时节目
      List<Time> lsTime = new ArrayList<Time>();
      Time time = new Time();
      time.setTimeStart("07:59:59");
      time.setTimeEnd("21:59:59");
      lsTime.add(time);
      programPlan.setTime(lsTime);
      programPlan.setUpdateDate(String.valueOf(new java.util.Date().getTime()));
      lsProgramPlan.add(programPlan);

      MulProgram mulProgram = new MulProgram();
      mulProgram.setClearCut(0);
      mulProgram.setClearTime(0);
      mulProgram.setClearOrder(1);
//      mulProgram.setDefaultPid("");
//      mulProgram.setOnlyCut(0);
      mulProgram.setProgram(lsProgramPlan);

//      lsMulProgram.add(mulProgram);


//      mulProgram.setProgram(lsProgram);

      //对象转为Json
      String pPlanJsonData = mapper.writeValueAsString(mulProgram);
      System.out.println(pPlanJsonData);
      byte[] pPlanDatatobytes = pPlanJsonData.getBytes();
      retValue = LedControlInf.INSTANCE.LV_SendProgramPlan2(iptobytes, pPlanDatatobytes, pDefResVideoFile.getBytes());
      System.out.println(retValue == 0 ? "节目更新计划发送成功" : "节目更新发送失败");


      retValue = LedControlInf.INSTANCE.LV_ProgramSendProcessEnd();
      System.out.println(retValue == 0 ? "节目缓存清理成功" : "节目缓存清理失败");
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  }

   private static void btMulProgramByPeriod_Click(byte[] iptobytes,int intStepTimeValue) throws ParseException
   {

 	   String screenName1 ="test1";
 	   String pProgramId = "20";
 	   String pProgramName = "20";

 	   byte[] pProgramIdToBytes = (pProgramId + "\0") .getBytes();
 	   byte[] pProgramNameToBytes = (pProgramName + "\0").getBytes();
 	   byte[] screenNameToBytes = (screenName1 + "\0") .getBytes();

 	   String rootPath = System.getProperty("user.dir")+"\\resources\\";

 	    byte[] errByt =new byte[2048];
 	   try {

 		 int retValue = 0;
       retValue = LedControlInf.INSTANCE.LV_ClearProgram(screenNameToBytes);
       System.out.println("LV_ClearProgram = " + retValue);

       Random rd = new Random();
       int pageId = rd.nextInt(100);
       //直行
       String src1 = rootPath + "10.bmp";

       //*****************第一步 添加节目页面***********************************************************************
       Page page = new Page();
       page.setPageId(pageId);
       page.setResolution("1920X1080");
       page.setBgColor("#000000");
       page.setBgImg("");
       page.setEqType("Q5");
       page.setPageTime(10);
       UUID uuid = UUID.randomUUID();
       page.setGuid(uuid.toString());

        //对象转为Json
       ObjectMapper mapper = new ObjectMapper();
       String pPageJson = mapper.writeValueAsString(page);
       System.out.println(pPageJson);

       byte[] pageJsontoBytes = pPageJson.getBytes();
       int resurt1 = LedControlInf.INSTANCE.LV_AddPageToProgram(screenNameToBytes, pProgramIdToBytes, pageJsontoBytes);

//       byte[] errByt = new byte[2048];
//       retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//
//       System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
       System.out.println(resurt1 == 0 ? "添加节目页面成功" : "添加节目页面失败");

       //*****************第二步 在节目页面上添加对应的显示区域*********************************************************

       //图片区域
       PictureArea a = new PictureArea();
       a.setId(1);
       a.setType(1);
       a.setBorderEffect(0);
       a.setBorderSW(0);
       a.setBorderSpeed(0);
       a.setBorderType(0);
       a.setLeft(0);
       a.setTop(0);
       a.setWidth(128);
       a.setHeight(128);
       a.setPauseTime(5);
       a.setRotation(0);
       a.setSiderType(6);
       List<SrcGroup> lsg = new ArrayList<SrcGroup>();
       a.setSrcGroup(lsg);

       SrcGroup s = new SrcGroup();
       s.setId(1);
       s.setSrc(src1);
       a.getSrcGroup().add(s);

       SrcGroup s1 = new SrcGroup();
       s1.setId(2);
       src1 = rootPath + "11.bmp";
       s1.setSrc(src1);
       a.getSrcGroup().add(s1);
       a.setzIndex(0);

       //对象转为Json
       String ajson = mapper.writeValueAsString(a);

       System.out.println(ajson);

       byte[] ajsontobytes = ajson.getBytes();
//       int resurt2 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, ajsontobytes);
       int resurt2 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, ajsontobytes);
//       retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//       System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
       System.out.println(resurt2 == 0 ? "添加图片区域成功" : "添加图片区域失败");


//     //视频区域
//       VideoArea videoArea = new VideoArea();
//       videoArea.setId(3);
//       videoArea.setType(0);
//       videoArea.setBorderEffect(1);
//       videoArea.setBorderSW(1);
//       videoArea.setBorderSpeed(1);
//       videoArea.setBorderType(9);
//       videoArea.setLeft(0);
//       videoArea.setTop(256);
//       videoArea.setWidth(288);
//       videoArea.setHeight(96);
//       videoArea.setPauseTime(5);
//       videoArea.setRotation(0);
//       videoArea.setSiderType(6);
//       List<SrcGroup> lsgVideoArea = new ArrayList<SrcGroup>();
//       videoArea.setSrcGroup(lsgVideoArea);
//
//       src1 = rootPath + "21.mp4";
//       SrcGroup sVideoArea = new SrcGroup();
//       sVideoArea.setId(1);
//       sVideoArea.setSrc(src1);
//       videoArea.getSrcGroup().add(sVideoArea);
//
//       SrcGroup sVideoArea1 = new SrcGroup();
//       sVideoArea1.setId(2);
//       src1 = rootPath + "23.mp4";
//       sVideoArea1.setSrc(src1);
//       videoArea.getSrcGroup().add(sVideoArea1);
//       videoArea.setzIndex(0);
//
//       //对象转为Json
//       String vjson = mapper.writeValueAsString(videoArea);
//
//       System.out.println(vjson);
//
//       byte[] vjsontobytes = vjson.getBytes();
////       int resurt3 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, vjsontobytes);
//       int resurt3 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, vjsontobytes);
////       retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
////       System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//       System.out.println(resurt3 == 0 ? "添加视频区域成功" : "添加视频区域失败");


       //文本区域
       TextArea textArea = new TextArea();
       //id
       textArea.setId(2);
   	//type Int 区域素材类型，字幕对应的类型为:2
       textArea.setType(2);
   	//borderSW Int 区域边框开关 1:开 0:关
       textArea.setBorderSW(0);
    	//borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
       textArea.setBorderEffect(0);
   	//颜色特效 0:无 1:水平渐变 2:垂直渐变 3:斜角渐变
       textArea.setColorEffect(0);
   	//borderSpeed int 区域边框速度 0~4
       textArea.setBorderSpeed(0);
   	//borderType Int 区域边框类型 0~9 详见附录
       textArea.setBorderType(0);
   	//left Int 区域 x 坐标点
       textArea.setLeft(256);
   	//top Int 区域 y 坐标点
       textArea.setTop(0);
   	//width Int 区域宽度
       textArea.setWidth(256);
   	//height Int 区域高度
       textArea.setHeight(64);
   	//background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
       textArea.setBackground("#000000");
   	//fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
       textArea.setFontColor("#00ff00");
   	//fontFamily String 文字字体,如”宋体”
       textArea.setFontFamily("宋体");
   	//fontSize Int 字体大小 12~128 ,单位 px
       textArea.setFontSize(48);
   	//italic Int 是否斜体 1:是 0:否
       textArea.setItalic(0);
   	// bold Int 是否粗体 1:是 0:否
       textArea.setBold(1);
   	//textLine Int 文字线 0:无 1:下划线 2:删除线
       textArea.setTextLine(0);
   	//lineHeight Int 行间距,多行时有效
       textArea.setLineHeight(5);
   	//pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
       textArea.setPauseTime(5);
   	//scrollSpeed Int 字幕滚动速度 0~14
       textArea.setScrollSpeed(2);
   	//siderType Int 滚动方式 0:静止 1:向左移动 2:向左连续移动 3:向右移动 4:向右连续移动
       textArea.setSiderType(2);
   	//textAlign Int 对齐方式 0:左,1:中间 2:右
       textArea.setTextAlign(0);

       textArea.setTextTop(0);

       String strTextInfo = "AAAA灵信视觉二次开发动态库文本发送";
//       String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
       textArea.setText(strTextInfo);
   	//textShow Int 字幕显示方式 1:单行 0:多行
       textArea.setTextShow(1);
   	//zIndex int 层级
   	textArea.setzIndex(0);

      //对象转为Json
      String tjson = mapper.writeValueAsString(textArea);

      System.out.println(tjson);

      byte[] tjsontobytes = tjson.getBytes();
//      int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
      int resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, tjsontobytes);
//      retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//      System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
      System.out.println(resurt4 == 0 ? "添加文本区域成功" : "添加文本区域失败");

      //*****************第三步 发送节目内容*********************************************************

   	//节目发送
//       retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(iptobytes);

       retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(screenNameToBytes,iptobytes,pProgramIdToBytes,pProgramNameToBytes,new byte[0]);
//       if(retValue != 0){
//          retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//          System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//       }
       System.out.println(retValue == 0 ? "节目内容发送成功" : "节目内容发送失败");

       //*****************第四步 发送节目计划,执行播放节目指令 *********************************************************
       String pDefResVideoFile ="\0";

//       MulProgram mulProgram = new MulProgram();

       List<MulProgram> lsMulProgram = new ArrayList<MulProgram>();

       List<ProgramPlan> lsProgramPlan = new ArrayList<ProgramPlan>();
       ProgramPlan programPlan = new ProgramPlan();
       programPlan.setCreateDate(String.valueOf(new java.util.Date().getTime()));
       List<Date> lsDate = new ArrayList<Date>();

       SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//       Calendar.getInstance().
       Date date = new Date();
       date.setDateStart(formatter.parse("2020-03-30").getTime());
       date.setDateEnd(formatter.parse("2020-04-30").getTime());
       lsDate.add(date);
       programPlan.setDate(lsDate);
       programPlan.setIsDefault(0);
       List lsPlanWeekDay = new ArrayList();
       for(int k=0;k<=6;k++){

           lsPlanWeekDay.add(1);
       }

       programPlan.setPlanWeekDay(lsPlanWeekDay);
       programPlan.setProgramId(pProgramId);
       programPlan.setProgramName(pProgramName);
       programPlan.setProgramType(3);//1:轮播节目(该类型节目最多只能1个) 2:插播节目 3:定时节目

       List<Time> lsTime = new ArrayList<Time>();
       Time time = new Time();
       SimpleDateFormat formatterTime = new SimpleDateFormat("HH:mm:ss");
       time.setTimeStart(formatterTime.format(Calendar.getInstance().getTime()));
       Calendar cal = Calendar.getInstance();
	   cal.setTime(Calendar.getInstance().getTime());
	   cal.add(Calendar.MINUTE, intStepTimeValue);
	   time.setTimeEnd(formatterTime.format(cal.getTime()));
       lsTime.add(time);
       programPlan.setTime(lsTime);

       programPlan.setUpdateDate(String.valueOf(new java.util.Date().getTime()));
       lsProgramPlan.add(programPlan);

       MulProgram mulProgram = new MulProgram();
       mulProgram.setClearCut(0);
       mulProgram.setClearTime(1);
       mulProgram.setClearOrder(0);
//       mulProgram.setDefaultPid("");
//       mulProgram.setOnlyCut(0);
       mulProgram.setProgram(lsProgramPlan);

//       lsMulProgram.add(mulProgram);


//       mulProgram.setProgram(lsProgram);

       //对象转为Json
       String pPlanJsonData = mapper.writeValueAsString(mulProgram);
       System.out.println(pPlanJsonData);
       byte[] pPlanDatatobytes = pPlanJsonData.getBytes();
       retValue = LedControlInf.INSTANCE.LV_SendProgramPlan2(iptobytes, pPlanDatatobytes, pDefResVideoFile.getBytes());
       System.out.println(retValue == 0 ? "节目更新计划发送成功" : "节目更新发送失败");


       retValue = LedControlInf.INSTANCE.LV_ProgramSendProcessEnd();
       System.out.println(retValue == 0 ? "节目缓存清理成功" : "节目缓存清理失败");
 		} catch (JsonGenerationException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		} catch (JsonMappingException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		} catch (IOException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
   }

   private static void btMulProgramByInsert_Click(byte[] iptobytes) throws ParseException
   {

 	   String screenName1 ="test1";
 	   String pProgramId = "21";
 	   String pProgramName = "21";

 	   byte[] pProgramIdToBytes = (pProgramId + "\0") .getBytes();
 	   byte[] pProgramNameToBytes = (pProgramName + "\0").getBytes();
 	   byte[] screenNameToBytes = (screenName1 + "\0") .getBytes();

 	   String rootPath = System.getProperty("user.dir")+"\\resources\\";

 	    byte[] errByt =new byte[2048];
 	   try {

 		 int retValue = 0;
       retValue = LedControlInf.INSTANCE.LV_ClearProgram(screenNameToBytes);
       System.out.println("LV_ClearProgram = " + retValue);

       Random rd = new Random();
       int pageId = rd.nextInt(100);
       //直行
       String src1 = rootPath + "88.jpg";

       //*****************第一步 添加节目页面***********************************************************************
       Page page = new Page();
       page.setPageId(pageId);
       page.setResolution("1920X1080");
       page.setBgColor("#000000");
       page.setBgImg("");
       page.setEqType("Q5");
       page.setPageTime(10);
       UUID uuid = UUID.randomUUID();
       page.setGuid(uuid.toString());

        //对象转为Json
       ObjectMapper mapper = new ObjectMapper();
       String pPageJson = mapper.writeValueAsString(page);
       System.out.println(pPageJson);

       byte[] pageJsontoBytes = pPageJson.getBytes();
       int resurt1 = LedControlInf.INSTANCE.LV_AddPageToProgram(screenNameToBytes, pProgramIdToBytes, pageJsontoBytes);

//       byte[] errByt = new byte[2048];
//       retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//
//       System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
       System.out.println(resurt1 == 0 ? "添加节目页面成功" : "添加节目页面失败");

       //*****************第二步 在节目页面上添加对应的显示区域*********************************************************

//       //图片区域
//       PictureArea a = new PictureArea();
//       a.setId(1);
//       a.setType(1);
//       a.setBorderEffect(0);
//       a.setBorderSW(0);
//       a.setBorderSpeed(0);
//       a.setBorderType(0);
//       a.setLeft(0);
//       a.setTop(0);
//       a.setWidth(128);
//       a.setHeight(128);
//       a.setPauseTime(5);
//       a.setRotation(0);
//       a.setSiderType(6);
//       List<SrcGroup> lsg = new ArrayList<SrcGroup>();
//       a.setSrcGroup(lsg);
//
//       SrcGroup s = new SrcGroup();
//       s.setId(1);
//       s.setSrc(src1);
//       a.getSrcGroup().add(s);
//
//       SrcGroup s1 = new SrcGroup();
//       s1.setId(2);
//       src1 = rootPath + "83.jpg";
//       s1.setSrc(src1);
//       a.getSrcGroup().add(s1);
//       a.setzIndex(0);
//
//       //对象转为Json
//       String ajson = mapper.writeValueAsString(a);
//
//       System.out.println(ajson);
//
//       byte[] ajsontobytes = ajson.getBytes();
////       int resurt2 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, ajsontobytes);
//       int resurt2 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, ajsontobytes);
////       retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
////       System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//       System.out.println(resurt2 == 0 ? "添加图片区域成功" : "添加图片区域失败");


     //视频区域
       VideoArea videoArea = new VideoArea();
       videoArea.setId(3);
       videoArea.setType(0);
       videoArea.setBorderEffect(1);
       videoArea.setBorderSW(1);
       videoArea.setBorderSpeed(1);
       videoArea.setBorderType(9);
       videoArea.setLeft(0);
       videoArea.setTop(64);
       videoArea.setWidth(1080);
       videoArea.setHeight(512);
       videoArea.setPauseTime(5);
       videoArea.setRotation(0);
       videoArea.setSiderType(6);
       List<SrcGroup> lsgVideoArea = new ArrayList<SrcGroup>();
       videoArea.setSrcGroup(lsgVideoArea);

       src1 = rootPath + "21.mp4";
       SrcGroup sVideoArea = new SrcGroup();
       sVideoArea.setId(1);
       sVideoArea.setSrc(src1);
       videoArea.getSrcGroup().add(sVideoArea);

       SrcGroup sVideoArea1 = new SrcGroup();
       sVideoArea1.setId(2);
       src1 = rootPath + "23.mp4";
       sVideoArea1.setSrc(src1);
       videoArea.getSrcGroup().add(sVideoArea1);

       SrcGroup sVideoArea2 = new SrcGroup();
       sVideoArea2.setId(2);
       src1 = rootPath + "yxceshi.mp4";
       sVideoArea2.setSrc(src1);
       videoArea.getSrcGroup().add(sVideoArea2);


       videoArea.setzIndex(0);

       //对象转为Json
       String vjson = mapper.writeValueAsString(videoArea);

       System.out.println(vjson);

       byte[] vjsontobytes = vjson.getBytes();
//       int resurt3 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, vjsontobytes);
       int resurt3 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, vjsontobytes);
//       retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//       System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
       System.out.println(resurt3 == 0 ? "添加视频区域成功" : "添加视频区域失败");


       //文本区域
       TextArea textArea = new TextArea();
       //id
       textArea.setId(2);
   	//type Int 区域素材类型，字幕对应的类型为:2
       textArea.setType(2);
   	//borderSW Int 区域边框开关 1:开 0:关
       textArea.setBorderSW(0);
    	//borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
       textArea.setBorderEffect(0);
   	//颜色特效 0:无 1:水平渐变 2:垂直渐变 3:斜角渐变
       textArea.setColorEffect(0);
   	//borderSpeed int 区域边框速度 0~4
       textArea.setBorderSpeed(0);
   	//borderType Int 区域边框类型 0~9 详见附录
       textArea.setBorderType(0);
   	//left Int 区域 x 坐标点
       textArea.setLeft(0);
   	//top Int 区域 y 坐标点
       textArea.setTop(0);
   	//width Int 区域宽度
       textArea.setWidth(256);
   	//height Int 区域高度
       textArea.setHeight(64);
   	//background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
       textArea.setBackground("#000000");
   	//fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
       textArea.setFontColor("#00ff00");
   	//fontFamily String 文字字体,如”宋体”
       textArea.setFontFamily("宋体");
   	//fontSize Int 字体大小 12~128 ,单位 px
       textArea.setFontSize(48);
   	//italic Int 是否斜体 1:是 0:否
       textArea.setItalic(0);
   	// bold Int 是否粗体 1:是 0:否
       textArea.setBold(1);
   	//textLine Int 文字线 0:无 1:下划线 2:删除线
       textArea.setTextLine(0);
   	//lineHeight Int 行间距,多行时有效
       textArea.setLineHeight(5);
   	//pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
       textArea.setPauseTime(5);
   	//scrollSpeed Int 字幕滚动速度 0~14
       textArea.setScrollSpeed(2);
   	//siderType Int 滚动方式 0:静止 1:向左移动 2:向左连续移动 3:向右移动 4:向右连续移动
       textArea.setSiderType(2);
   	//textAlign Int 对齐方式 0:左,1:中间 2:右
       textArea.setTextAlign(0);

       textArea.setTextTop(0);

       String strTextInfo = "AAAA灵信视觉二次开发动态库文本发送";
//       String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
       textArea.setText(strTextInfo);
   	//textShow Int 字幕显示方式 1:单行 0:多行
       textArea.setTextShow(1);
   	//zIndex int 层级
   	textArea.setzIndex(0);

      //对象转为Json
      String tjson = mapper.writeValueAsString(textArea);

      System.out.println(tjson);

      byte[] tjsontobytes = tjson.getBytes();
//      int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
      int resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, tjsontobytes);
//      retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//      System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
      System.out.println(resurt4 == 0 ? "添加文本区域成功" : "添加文本区域失败");

      //*****************第三步 发送节目内容*********************************************************

   	//节目发送
//       retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(iptobytes);

       retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(screenNameToBytes,iptobytes,pProgramIdToBytes,pProgramNameToBytes,new byte[0]);
//       if(retValue != 0){
//          retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//          System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//       }
       System.out.println(retValue == 0 ? "节目内容发送成功" : "节目内容发送失败");

       //*****************第四步 发送节目计划,执行播放节目指令 *********************************************************
       String pDefResVideoFile ="\0";

//       MulProgram mulProgram = new MulProgram();

       List<MulProgram> lsMulProgram = new ArrayList<MulProgram>();

       List<ProgramPlan> lsProgramPlan = new ArrayList<ProgramPlan>();
       ProgramPlan programPlan = new ProgramPlan();
       programPlan.setCreateDate(String.valueOf(new java.util.Date().getTime()));
       List<Date> lsDate = new ArrayList<Date>();

       SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//       Calendar.getInstance().
       Date date = new Date();
       date.setDateStart(formatter.parse("2020-03-30").getTime());
       date.setDateEnd(formatter.parse("2020-04-30").getTime());
       lsDate.add(date);
       programPlan.setDate(lsDate);
       programPlan.setIsDefault(0);
       List lsPlanWeekDay = new ArrayList();
       for(int k=0;k<=6;k++){

           lsPlanWeekDay.add(1);
       }

       programPlan.setPlanWeekDay(lsPlanWeekDay);
       programPlan.setProgramId(pProgramId);
       programPlan.setProgramName(pProgramName);
       programPlan.setProgramType(2);//1:轮播节目(该类型节目最多只能1个) 2:插播节目 3:定时节目
       List<Time> lsTime = new ArrayList<Time>();

       Time time = new Time();
       time.setTimeStart("08:30:00");
       time.setTimeEnd("10:00:00");
       lsTime.add(time);

       Time time1 = new Time();
       time1.setTimeStart("12:00:00");
       time1.setTimeEnd("14:00:00");
       lsTime.add(time1);

       Time time2 = new Time();
       time2.setTimeStart("17:00:00");
       time2.setTimeEnd("17:30:00");
       lsTime.add(time2);

       Time time3 = new Time();
       time3.setTimeStart("18:30:00");
       time3.setTimeEnd("23:59:59");
       lsTime.add(time3);

       programPlan.setTime(lsTime);


       programPlan.setUpdateDate(String.valueOf(new java.util.Date().getTime()));
       lsProgramPlan.add(programPlan);

       MulProgram mulProgram = new MulProgram();
       mulProgram.setClearCut(1);
       mulProgram.setClearTime(0);
       mulProgram.setClearOrder(0);
//       mulProgram.setDefaultPid("");
//       mulProgram.setOnlyCut(0);
       mulProgram.setProgram(lsProgramPlan);

//       lsMulProgram.add(mulProgram);


//       mulProgram.setProgram(lsProgram);

       //对象转为Json
       String pPlanJsonData = mapper.writeValueAsString(mulProgram);
       System.out.println(pPlanJsonData);
       byte[] pPlanDatatobytes = pPlanJsonData.getBytes();
       retValue = LedControlInf.INSTANCE.LV_SendProgramPlan2(iptobytes, pPlanDatatobytes, pDefResVideoFile.getBytes());
       System.out.println(retValue == 0 ? "节目更新计划发送成功" : "节目更新发送失败");


       retValue = LedControlInf.INSTANCE.LV_ProgramSendProcessEnd();
       System.out.println(retValue == 0 ? "节目缓存清理成功" : "节目缓存清理失败");
 		} catch (JsonGenerationException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		} catch (JsonMappingException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		} catch (IOException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
   }
}
